/*package com.longchat.service.impl.system;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.longchat.dto.system.NavibarInfo;
import com.longchat.repository.RoleJpaRepository;
import com.longchat.repository.SysUserJpaRepository;
import com.longchat.service.inter.system.IPermissionService;

@Service
public class PermissionService implements IPermissionService {

	@Autowired
	private RoleJpaRepository roleJpaRepository;
	@Autowired
	private SysUserJpaRepository sysUserJpaRepository;

	@Override
	public List<Resource> findPermissinsByUserName(String userName) {
		return roleJpaRepository.queryPermissionByUserName(userName);
	}
	@Override
	public List<MenuInfo> findPermissionsMenus(String userName) {
		SysUser sysUser = sysUserJpaRepository.findByUserName(userName);
		List<Resource> resources = UserType.SUPER_USER.equals(sysUser.getType())?
				resourceJpaRepository.findAllMenu(ResourceType.MENU):
				roleJpaRepository.queryPermissionMenuByUserName(userName,ResourceType.MENU);
		List<MenuInfo> menus = new ArrayList<MenuInfo>();
		for(Resource r:resources){
			MenuInfo menu = new MenuInfo();
			menu.setName(r.getName());
			menu.setUrl(r.getUrl());
			menu.setIcon(r.getIcon());
			menus.add(menu);
		}
		return menus;
	}
	@Override
	public List<NavibarInfo> findNavibars(String userName) {
		List<NavibarInfo> navibars = new ArrayList<NavibarInfo>();
		SysUser sysUser = sysUserJpaRepository.findByUserName(userName);
		List<Resource> resources = UserType.SUPER_USER.equals(sysUser.getType())?
				resourceJpaRepository.findAllMenu(ResourceType.MENU):
				roleJpaRepository.queryPermissionMenuByUserName(userName,ResourceType.MENU);
		List<NavibarInfo> queryNavibars = new ArrayList<NavibarInfo>();
		for(Resource r:resources){
			NavibarInfo bar = new NavibarInfo();
			bar.setName(r.getName());
			bar.setUrl(r.getUrl());
			bar.setIcon(r.getIcon());
			bar.setId(r.getId());
			bar.setPid(r.getParent()!=null?r.getParent().getId():null);
			queryNavibars.add(bar);
		}
		for(int i=0;i<queryNavibars.size();i++){
			NavibarInfo n = queryNavibars.get(i);
			if(null==n.getPid()){
				navibars.add(n);
				queryNavibars.remove(i);
				navibarShowInLevel(queryNavibars, n);
				i--;
			}
			if(n.getPid()!=null){
				continue;
			}
			
		}
		return navibars;
	}
	private void navibarShowInLevel(List<NavibarInfo> navbars,NavibarInfo parent){
		List<NavibarInfo> childrens = new ArrayList<NavibarInfo>();
		for(int i=0;i<navbars.size();i++){
			if(parent.getId().equals(navbars.get(i).getPid())){
				NavibarInfo children = navbars.get(i);
				childrens.add(children);
				navbars.remove(i);
				if(!CollectionUtils.isEmpty(navbars)){
					navibarShowInLevel(navbars, children);
				}
				i--;
			}
			if(i==navbars.size()-1){
				if(!CollectionUtils.isEmpty(childrens)){
					parent.setChildrens(childrens);
				}
			}
		}
	}
}
*/